<?php
/**
 * Created by PhpStorm.
 * User: lizx
 * Date: 2018/3/13
 * Time: 9:16
 */

namespace app\api\service;

use app\common\Service;

class CommonFuncsService extends Service
{
    public function checkPhone($phone)
    {
        $number = str_replace('-', '', $phone);
        if (!preg_match('/1\d{10}$/', $number)) {
            return false;
        }
        return substr($number, -11);
    }


    public function getIDCard($idcard)
    {
        if (!preg_match('/[0-9xX]{15}$/', $idcard) && !preg_match('/[0-9xX]{18}$/', $idcard)) {
            return false;
        }
        require_once(dirname(__DIR__).'/../../extend/idcard.php');
        if(strlen($idcard)==15)$idcard = idcard_15to18($idcard);
        if(!idcard_checksum18($idcard))return false;
        return $idcard;
    }
}